package com.example.api.controller;

import java.util.Map;

import javax.servlet.http.HttpSession;

import org.assertj.core.data.Index;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@RequestMapping("/page")
@Controller
public class DatabaseInfoPageController {

	/**
	 * 主页面
	 * @return
	 */
	@RequestMapping("/mainPage")
	public String mainPage(HttpSession session,Map<String, String>map) {
		String username = (String) session.getAttribute("username");
		map.put("userName", username);
		return "main";
	}
	
	/**
	 * 数据库配置界面
	 * @return
	 */
	@RequestMapping("/databaseConfigPage")
	public String databaseConfigPage() {
		return "databaseConfigPage";
	}
	
	/**
	 * 表的列表页面
	 * @param connectionId
	 * @param databaseName
	 * @param model
	 * @return
	 */
	@RequestMapping("/databaseWithTableInfoPage")
	public String databaseWithTableInfoPage(String connectionId,String databaseName,Model model) {
		model.addAttribute("connectionId", connectionId);
		model.addAttribute("databaseName", databaseName);
		return "databaseWithTableInfo";
	}
	
	/**
	 * 视图的列表页面
	 * @param connectionId
	 * @param databaseName
	 * @param model
	 * @return
	 */
	@RequestMapping("/viewListPage")
	public String viewListPage(String connectionId,String databaseName,Model model) {
		model.addAttribute("connectionId", connectionId);
		model.addAttribute("databaseName", databaseName);
		return "viewList";
	}
	
	/**
	 * 表字段信息页面
	 * @param databaseName
	 * @param connectionId
	 * @param tableName
	 * @param model
	 * @return
	 */
	@RequestMapping("tableInfoPage")
	public String tableInfoPage(String databaseName, String connectionId,String tableName,Model model) {
		model.addAttribute("databaseName", databaseName);
		model.addAttribute("connectionId", connectionId);
		model.addAttribute("tableName", tableName);
		return "tableInfo";
	}
	/**
	 * 视图字段信息页面
	 * @param databaseName
	 * @param connectionId
	 * @param tableName
	 * @param model
	 * @return
	 */
	@RequestMapping("viewFieldsInfoPage")
	public String viewFieldsInfoPage(String databaseName, String connectionId,String viewName,Model model) {
		model.addAttribute("databaseName", databaseName);
		model.addAttribute("connectionId", connectionId);
		model.addAttribute("viewName", viewName);
		return "viewFieldsInfo";
	}
	
	@RequestMapping("/addConnectionConfigPage")
	public String addConnectionConfigPage() {
		return "addConnectionConfigPage";
	}
}
